package com.blyat.xsoft.kernel.restful.exception.code;


import com.blyat.xsoft.kernel.exception.code.ErrorResult;

/**
 * @author syh
 * @date 2019/10/16
 **/
public enum ServiceErrorResult implements ErrorResult {

    /**
     * api服务异常
     */
    CHECK_EXCEPTION("20000", "错误:%s"),
    PARAMETER_NULL_EXCEPTION("20100", "参数[%s]不能为空!"),
    ENTITY_EXISTS("20101", "[%s]已存在!"),
    ENTITY_NOT_EXISTS("20102", "%s不存在"),

    /**
     * redis异常
     */
    REDIS_ERROR("30000", "redis异常:%s"),

    /**
     * kafka 生产者异常
     */
    KAFKA_INVALID_CONTENT("50000", "消息内容格式有误！"),
    KAFKA_INVALID_SCENE("50001", "无效的事件类型：%s"),
    KAFKA_INVALID_TOKEN("50002", "无效的授权码: %s"),
    KAFKA_INVALID_AUTH("50003", "暂无权限：%s"),
    KAFKA_PRODUCER_SEND_ERROR("50004", "Kafka发送异常:%s"),
    KAFKA_PRODUCER_SEND_BLACK("50005", "该用户已经被加入黑名单"),
    KAFKA_PRODUCER_SEND_REPEAT("50005", "消息重复发送"),
    KAFKA_INVALID_SCENE_NULL("50006", "事件号不能为空：%s"),
    KAFKA_INVALID_CONTENT_NULL("50007", "消息内容不能为空！"),
    KAFKA_INVALID_BATCHNO_NULL("50008", "消息流水号不能为空！"),

    /**
     * kafka 消费者异常
     */
    KAFKA_ADAPTER_NOT_FOUND("50100", "未知kafka消息topic:%s"),
    KAFKA_SUBMITTER_INIT_FAIL("50101", "kafka提交器初始化失败:%s"),
    KAFKA_CONSUMER_SEND_ERROR("50104", "Kafka发送异常:%s"),
    KAFKA_CONSUMER_EMPTY_INTERFACE("50105", "%s"),

    ;

    String result, message;

    ServiceErrorResult(String result, String message) {
        this.result = result;
        this.message = message;
    }

    @Override
    public String getResult() {
        return this.result;
    }

    @Override
    public String getMessage(Object... args) {
        if (args == null || args.length <= 0) return this.message;

        try {
            return String.format(this.message, args);
        } catch (Exception e) {
            return this.message;
        }
    }
}
